package com.partsoft.dits.mq;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.util.Assert;

public class BaseMQQueueDescriptor implements Cloneable, BeanNameAware {
	
	private String id;
	
	private String connectPool;

	private String queue;
	
	private String queueManager;
	
	private String description;
	
	private int ordinal = 0;
	
	private String title;
	
	public BaseMQQueueDescriptor(){}
	
	public BaseMQQueueDescriptor(String queueManager, String queueName) {
		setQueueManager(queueManager);
		setQueue(queueName);
	}
	
	public BaseMQQueueDescriptor(String queueManager, String queueName, String description) {
		setQueueManager(queueManager);
		setQueue(queueName);
		setDescription(description);
	}
	
	public String getTitle() {
		return title == null ? "" : title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getQueue() {
		return queue;
	}

	public void setQueue(String queueName) {
		Assert.notNull(queueName);
		this.queue = queueName;
	}

	public String getQueueManager() {
		return queueManager;
	}

	public void setQueueManager(String queueManager) {
		Assert.notNull(queueManager);
		this.queueManager = queueManager;
	}

	public String getDescription() {
		return description == null ? "" : description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	public int getOrdinal() {
		return ordinal;
	}

	public void setOrdinal(int ordinal) {
		this.ordinal = ordinal;
	}

	public String getConnectPool() {
		return connectPool;
	}

	public void setConnectPool(String connectPool) {
		this.connectPool = connectPool;
	}

	@Override
	public BaseMQQueueDescriptor clone() {
		try {
			return (BaseMQQueueDescriptor) super.clone();
		} catch (CloneNotSupportedException e) {
			return null;
		}
	}
	

	@Override
	public String toString() {
		return "BaseMQQueueDescriptor [getQueueManager()=" + getQueueManager()
				+ ", getQueueName()=" + getQueue() + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		String id = getId();
		result = prime * result
				+ ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BaseMQQueueDescriptor other = (BaseMQQueueDescriptor) obj;
		String id = getId();
		String oid = other.getId();
		if (id == null) {
			if (oid != null)
				return false;
		} else if (!id.equals(oid))
			return false;
		return true;
	}

	public void setBeanName(String beanName) {
		setId(beanName);
	}
	
}
